"""
@File    : logger.py
@Time    : 2021/10/29 0:29
@Author  : chenhuayan
@Software: PyCharm
"""
# !/usr/bin/env python3
# -*- coding: utf-8 -*-
import logbook
from app import neverGiveUp
from .decorator import SingletonDecorator


@SingletonDecorator
class Log(object):
    handler = None

    def __init__(self, name='neverGiveUp', filename=neverGiveUp.config['LOG_NAME']):
        self.handler = logbook.FileHandler(filename, encoding='utf-8')
        logbook.set_datetime_format('local')
        self.logger = logbook.Logger(name)
        self.handler.push_application()

    def info(self, *args, **kwargs):
        return self.logger.info(*args, **kwargs)

    def error(self, *args, **kwargs):
        return self.logger.error(*args, **kwargs)

    def warning(self, *args, **kwargs):
        return self.logger.warning(*args, **kwargs)

    def debug(self, *args, **kwargs):
        return self.logger.debug(*args, **kwargs)
